package com.lemon.service.impl;

import com.baomidou.mybatisplus.core.toolkit.ObjectUtils;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.lemon.domain.LogisticsPrice;
import com.lemon.domain.PageResult;
import com.lemon.mapper.LogisticsPriceMapper;
import com.lemon.service.LogisticsPriceService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class LogisticsPriceServiceImpl extends ServiceImpl<LogisticsPriceMapper, LogisticsPrice> implements LogisticsPriceService {

    @Autowired
    private LogisticsPriceMapper logisticsPriceMapper;

    @Override
    public PageResult getPage(Integer page, Integer pageSize, Integer category, Integer logisticsCompanyId) {
        PageHelper.startPage(page,pageSize);
        List<LogisticsPrice> logisticsPrices = logisticsPriceMapper.selectList(Wrappers.<LogisticsPrice>lambdaQuery().eq(ObjectUtils.isNotEmpty(category), LogisticsPrice::getCategory, category).eq(ObjectUtils.isNotEmpty(logisticsCompanyId), LogisticsPrice::getLogisticsCompanyId, logisticsCompanyId));
        Page page1 = (Page) logisticsPrices;
        return new PageResult(page1.getTotal(),page1.getResult());
    }
}
